/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package aptech.semester.code.gui;

import aptech.semester.code.common.Role;
import aptech.semester.code.data.AccountList;
import aptech.semester.code.data.DepartmentList;
import aptech.semester.code.data.EmployeeList;
import aptech.semester.code.entity.AccountEntity;
import aptech.semester.code.entity.DepartmentEntity;
import aptech.semester.code.entity.EmployeeEntity;
import aptech.semester.code.item.DepartmentComboItem;
import aptech.semester.code.item.RoleComboItem;
import java.util.ArrayList;
import java.util.List;
import java.util.TreeMap;
import javax.swing.JOptionPane;
import javax.swing.RowFilter;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableModel;
import javax.swing.table.TableRowSorter;

/**
 *
 * @author vi
 */
public class ManageAccount extends javax.swing.JInternalFrame {

    /**
     * Creates new form ManageAccount
     */
    public ManageAccount(MainScreen main) {
        initComponents();
        initData();
        this.employeeLoginId = main.getLoginEmployee().getEmployeeId();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jSplitPane1 = new javax.swing.JSplitPane();
        leftPanel = new javax.swing.JPanel();
        scrollViewEmployee = new javax.swing.JScrollPane();
        tblViewEmployee = new javax.swing.JTable();
        txtSearchEmployee = new javax.swing.JTextField();
        btnSearchEmp = new javax.swing.JButton();
        cbSearchDepartment = new javax.swing.JComboBox();
        btnResetTable = new javax.swing.JButton();
        rightPanel = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        txtUserName = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        txtPassword = new javax.swing.JPasswordField();
        jLabel3 = new javax.swing.JLabel();
        cbRole = new javax.swing.JComboBox();
        jLabel4 = new javax.swing.JLabel();
        txtConfirmPassword = new javax.swing.JPasswordField();
        btnSave = new javax.swing.JButton();
        btnCancel = new javax.swing.JButton();
        btnCreateAcc = new javax.swing.JButton();
        btnDelete = new javax.swing.JButton();

        setClosable(true);
        setTitle("Manage Account");
        setPreferredSize(new java.awt.Dimension(1000, 600));

        jSplitPane1.setDividerLocation(300);

        leftPanel.setBorder(javax.swing.BorderFactory.createTitledBorder("Employee List"));

        tblViewEmployee.setAutoCreateRowSorter(true);
        tblViewEmployee.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {
                "Employee ID", "Emloyee name", "Position", "Department"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, false, false, false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        tblViewEmployee.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mousePressed(java.awt.event.MouseEvent evt) {
                tblViewEmployeeMousePressed(evt);
            }
        });
        scrollViewEmployee.setViewportView(tblViewEmployee);

        txtSearchEmployee.setToolTipText("input name of employee");
        txtSearchEmployee.setName(""); // NOI18N
        txtSearchEmployee.setRequestFocusEnabled(false);

        btnSearchEmp.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/icon/btn_search.png"))); // NOI18N
        btnSearchEmp.setText("Search");
        btnSearchEmp.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnSearchEmpActionPerformed(evt);
            }
        });

        cbSearchDepartment.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "---Select---" }));
        cbSearchDepartment.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                cbSearchDepartmentActionPerformed(evt);
            }
        });

        btnResetTable.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/icon/reset.gif"))); // NOI18N
        btnResetTable.setText("Reset");
        btnResetTable.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnResetTableActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout leftPanelLayout = new javax.swing.GroupLayout(leftPanel);
        leftPanel.setLayout(leftPanelLayout);
        leftPanelLayout.setHorizontalGroup(
            leftPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, leftPanelLayout.createSequentialGroup()
                .addGroup(leftPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(cbSearchDepartment, javax.swing.GroupLayout.Alignment.LEADING, 0, 166, Short.MAX_VALUE)
                    .addComponent(txtSearchEmployee))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btnSearchEmp, javax.swing.GroupLayout.PREFERRED_SIZE, 85, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
            .addComponent(scrollViewEmployee, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
            .addGroup(leftPanelLayout.createSequentialGroup()
                .addGap(79, 79, 79)
                .addComponent(btnResetTable)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        leftPanelLayout.setVerticalGroup(
            leftPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(leftPanelLayout.createSequentialGroup()
                .addGroup(leftPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtSearchEmployee, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(btnSearchEmp))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(cbSearchDepartment, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(scrollViewEmployee, javax.swing.GroupLayout.DEFAULT_SIZE, 440, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(btnResetTable)
                .addGap(4, 4, 4))
        );

        jSplitPane1.setLeftComponent(leftPanel);

        rightPanel.setBorder(javax.swing.BorderFactory.createTitledBorder("Account"));

        jLabel1.setText("Username");

        jLabel2.setText("Password");

        jLabel3.setText("Role");

        jLabel4.setText("Confirm Password");

        btnSave.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/icon/save.png"))); // NOI18N
        btnSave.setText("Save");
        btnSave.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnSaveActionPerformed(evt);
            }
        });

        btnCancel.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/icon/btn_cancel.png"))); // NOI18N
        btnCancel.setText("Cancel");
        btnCancel.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCancelActionPerformed(evt);
            }
        });

        btnCreateAcc.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/icon/add.png"))); // NOI18N
        btnCreateAcc.setText("Create Account");
        btnCreateAcc.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnCreateAccActionPerformed(evt);
            }
        });

        btnDelete.setIcon(new javax.swing.ImageIcon(getClass().getResource("/images/icon/delete.png"))); // NOI18N
        btnDelete.setText("Delete Account");
        btnDelete.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnDeleteActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout rightPanelLayout = new javax.swing.GroupLayout(rightPanel);
        rightPanel.setLayout(rightPanelLayout);
        rightPanelLayout.setHorizontalGroup(
            rightPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(rightPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(rightPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(rightPanelLayout.createSequentialGroup()
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 198, Short.MAX_VALUE)
                        .addComponent(btnCancel)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnDelete)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnCreateAcc)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(btnSave))
                    .addGroup(rightPanelLayout.createSequentialGroup()
                        .addGroup(rightPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel2)
                            .addComponent(jLabel1)
                            .addComponent(jLabel3)
                            .addComponent(jLabel4))
                        .addGap(20, 20, 20)
                        .addGroup(rightPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(txtUserName, javax.swing.GroupLayout.Alignment.TRAILING)
                            .addComponent(txtConfirmPassword)
                            .addComponent(txtPassword)
                            .addComponent(cbRole, 0, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))))
                .addContainerGap())
        );
        rightPanelLayout.setVerticalGroup(
            rightPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(rightPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(rightPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(txtUserName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(rightPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel2)
                    .addComponent(txtPassword, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(rightPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(txtConfirmPassword, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(rightPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel3)
                    .addComponent(cbRole, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(rightPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnSave)
                    .addComponent(btnCancel)
                    .addComponent(btnCreateAcc)
                    .addComponent(btnDelete))
                .addContainerGap(396, Short.MAX_VALUE))
        );

        jSplitPane1.setRightComponent(rightPanel);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jSplitPane1)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jSplitPane1)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void tblViewEmployeeMousePressed(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tblViewEmployeeMousePressed
        selectEmployee();
    }//GEN-LAST:event_tblViewEmployeeMousePressed

    private void btnSearchEmpActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSearchEmpActionPerformed
        

        String dept =(String) cbSearchDepartment.getSelectedItem().toString();
        String dk = txtSearchEmployee.getText().trim();
        sorter = (TableRowSorter<TableModel>) tblViewEmployee.getRowSorter();
        List filter = new ArrayList();
        if (txtSearchEmployee.getText().trim().equals("") && cbSearchDepartment.getSelectedIndex() == 0) {
            JOptionPane.showMessageDialog(null, "Please input condition to search !");
            txtSearchEmployee.requestFocus();
        } else  {

            if (!txtSearchEmployee.getText().trim().equals("") && cbSearchDepartment.getSelectedIndex() == 0) {
                filter.add(RowFilter.regexFilter(dk, 1));
                sorter.setRowFilter(RowFilter.andFilter(filter));
                txtSearchEmployee.requestFocus();
            }

            if (txtSearchEmployee.getText().trim().equals("") && cbSearchDepartment.getSelectedIndex() != 0) {
                filter.add(RowFilter.regexFilter(dept, 3));
                sorter.setRowFilter(RowFilter.andFilter(filter));
                txtSearchEmployee.requestFocus();
            }
            if (!txtSearchEmployee.getText().trim().equals("") && cbSearchDepartment.getSelectedIndex() != 0) {
                filter.add(RowFilter.regexFilter(dk, 1));
                filter.add(RowFilter.regexFilter(dept, 3));
                sorter.setRowFilter(RowFilter.andFilter(filter));
                txtSearchEmployee.requestFocus();
            }
            if(tblViewEmployee.getRowCount()==0) {
                JOptionPane.showMessageDialog(null, "Not found any result !");
                return;

            }
        }
    }//GEN-LAST:event_btnSearchEmpActionPerformed

    private void cbSearchDepartmentActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_cbSearchDepartmentActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_cbSearchDepartmentActionPerformed

    private void btnResetTableActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnResetTableActionPerformed
        txtSearchEmployee.setText("");
        cbSearchDepartment.setSelectedIndex(0);
        sorter.setRowFilter(null);
        txtSearchEmployee.requestFocus();
        return;
    }//GEN-LAST:event_btnResetTableActionPerformed

    private void btnCreateAccActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCreateAccActionPerformed
        statusHaveAccount();
        AccountEntity acc = new AccountEntity();
        fillData(acc);
        
    }//GEN-LAST:event_btnCreateAccActionPerformed

    private void btnSaveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnSaveActionPerformed
        if (validation()) {
            String userName = txtUserName.getText();
            String password = String.valueOf(txtPassword.getPassword());
            RoleComboItem item = (RoleComboItem)cbRole.getSelectedItem();  
            int role = item.getValue();
            if (isUpdate) {
                selectedAccount.setUserName(userName);
                selectedAccount.setPassword(password);
                selectedAccount.setRole(role);
                boolean update = new AccountList().update(selectedAccount);
                if (update) {
                    JOptionPane.showMessageDialog(null, "Update Successful !");
                } else {
                    JOptionPane.showMessageDialog(null, "Update Failed !");
                }
            } else {
                AccountEntity acc = new AccountEntity();
                acc.setUserName(userName);
                acc.setPassword(password);
                acc.setEmployeeId(employeeId);
                acc.setRole(role);
                boolean insert = new AccountList().insert(acc);
                if (insert) {
                    JOptionPane.showMessageDialog(null, "Insert Successful !");
                } else {
                    JOptionPane.showMessageDialog(null, "Insert Failed !");
                }
            }
        }
        selectEmployee();
    }//GEN-LAST:event_btnSaveActionPerformed

    private void btnCancelActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnCancelActionPerformed
        selectEmployee();
    }//GEN-LAST:event_btnCancelActionPerformed

    private void btnDeleteActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnDeleteActionPerformed
        int rd = JOptionPane.showConfirmDialog(null, "Are you sure?", "Notify", JOptionPane.OK_CANCEL_OPTION);
            if (rd == JOptionPane.OK_OPTION) {
                if (new AccountList().delete(selectedAccount.getAccountId())) {
                    
                    JOptionPane.showMessageDialog(null, "Delete successful !");
                    selectEmployee();
                } else {
                    JOptionPane.showMessageDialog(null, "Delete fail !");
                }
            }
    }//GEN-LAST:event_btnDeleteActionPerformed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnCancel;
    private javax.swing.JButton btnCreateAcc;
    private javax.swing.JButton btnDelete;
    private javax.swing.JButton btnResetTable;
    private javax.swing.JButton btnSave;
    private javax.swing.JButton btnSearchEmp;
    private javax.swing.JComboBox cbRole;
    private javax.swing.JComboBox cbSearchDepartment;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JSplitPane jSplitPane1;
    private javax.swing.JPanel leftPanel;
    private javax.swing.JPanel rightPanel;
    private javax.swing.JScrollPane scrollViewEmployee;
    private javax.swing.JTable tblViewEmployee;
    private javax.swing.JPasswordField txtConfirmPassword;
    private javax.swing.JPasswordField txtPassword;
    private javax.swing.JTextField txtSearchEmployee;
    private javax.swing.JTextField txtUserName;
    // End of variables declaration//GEN-END:variables
    DefaultTableModel model; 
    private List<DepartmentEntity> listDept;
    TableRowSorter<TableModel> sorter;
    private AccountEntity selectedAccount = new AccountEntity() ;
    private TreeMap mapEmployee = new TreeMap<String, EmployeeEntity>();
    private boolean isUpdate;
    private String employeeId;
    private String employeeLoginId;
    private void initData() {
        sorter = (TableRowSorter<TableModel>) tblViewEmployee.getRowSorter();;
        this.loadDataTableEmployee();
        // binding data for department
        listDept = new DepartmentList().getAllDepartment();
        for (DepartmentEntity dept : listDept) {
            cbSearchDepartment.addItem(new DepartmentComboItem(dept));
        }
        
        cbRole.addItem(new RoleComboItem(Role.ROLE_ADMIN));
        cbRole.addItem(new RoleComboItem(Role.ROLE_HR));
        cbRole.addItem(new RoleComboItem(Role.ROLE_MANAGER));
        cbRole.addItem(new RoleComboItem(Role.ROLE_STAFF));
        
        statusNoAccount();
        btnCreateAcc.setEnabled(false);
    }
    private void loadDataTableEmployee() {
        // binding data for employee list      
        model = (DefaultTableModel)tblViewEmployee.getModel();
        model.setRowCount(0);
        List<EmployeeEntity> listEmp = new EmployeeList().getList();
        for (EmployeeEntity item : listEmp) {
            mapEmployee.put(item.getEmployeeId(), item);
            model.addRow(item.toVector1());
        }
        
    }
    
    private void fillData(AccountEntity acc) {
        txtUserName.setText(acc.getUserName());
        txtPassword.setText(acc.getPassword());
        txtConfirmPassword.setText(acc.getPassword());
        for (int i = 0; i < cbRole.getItemCount(); i ++) {
            RoleComboItem item = (RoleComboItem)cbRole.getItemAt(i);
            if (item.getValue() == acc.getRole()) {
                cbRole.setSelectedIndex(i);
                break;
            }
        }
    }
    
    private void statusNoAccount() {
        txtUserName.setText("");
        txtUserName.setEnabled(false);
        txtPassword.setText("password");
        txtPassword.setEnabled(false);
        txtConfirmPassword.setText("password");
        txtConfirmPassword.setEnabled(false);
        cbRole.setSelectedIndex(0);
        cbRole.setEnabled(false);
        btnSave.setEnabled(false);
        btnCancel.setEnabled(false);
        btnCreateAcc.setEnabled(true);
        btnDelete.setEnabled(false);
    }
    
    private void statusHaveAccount() {
        txtPassword.setEnabled(true);
        txtUserName.setEnabled(true);
        txtConfirmPassword.setEnabled(true);
        cbRole.setEnabled(true);
        btnSave.setEnabled(true);
        btnCancel.setEnabled(true);
        btnCreateAcc.setEnabled(false);
        
    }
    
    private boolean validation() {
        if(txtUserName.getText().trim().equals("")) {
            JOptionPane.showMessageDialog(null, "Username can not blank !");
            txtUserName.requestFocus();
            return false;
        }
        
        if(txtPassword.getPassword().length <= 0) {
            JOptionPane.showMessageDialog(null, "Password can not blank !");
            txtPassword.requestFocus();
            return false;
        }
        if (!String.valueOf(txtPassword.getPassword()).equals(String.valueOf(txtConfirmPassword.getPassword()))) {
            JOptionPane.showMessageDialog(null, "Confirm Password not match !");
            txtPassword.requestFocus();
            return false;
        }
        return true;
    }
    
    private void selectEmployee() {
        int r = tblViewEmployee.getSelectedRow();
        if(r<0) {
            return;
        } else {
            employeeId = tblViewEmployee.getValueAt(r,0).toString();

            selectedAccount = new AccountList().getAccountByEmployeeId(employeeId);
            if (selectedAccount.getAccountId() > 0) {
                isUpdate = true;
                
                statusHaveAccount();
                if (!employeeLoginId.equals(employeeId)) {
                    btnDelete.setEnabled(true);
                } else {
                    btnDelete.setEnabled(false);
                }
                fillData(selectedAccount);
            } else {
                btnDelete.setEnabled(false);
                isUpdate = false;
                statusNoAccount();
            }
            
            
        }
    }
    
    private int getIndexOfDept(String name) {
        int index = 0;
        for (int i = 0; i< listDept.size(); i++) {
            if (listDept.get(i).getDepartmentName().equals(name)) {
                index = i;
                break;
            }
        }
        return index;
    }
}
